﻿CREATE FUNCTION dbo.NameSpaces_Local (@NS nvarchar(2048) = NULL)  
RETURNS @NSs TABLE (NameSpace nvarchar(128))  
AS BEGIN  
  
IF @NS IS NULL SET @NS = dbo.UserNameSpace()  
DECLARE @Pos int SET @Pos = 1  
  
INSERT INTO @NSs SELECT ''  
  
WHILE @Pos > 0 AND @NS > '' BEGIN  
  
 SET @Pos = CASE CHARINDEX('\',@NS,@Pos+1) WHEN 0 THEN CHARINDEX('/',@NS,@Pos+1) ELSE CHARINDEX('\',@NS,@Pos+1) END  
  
 INSERT INTO @NSs  
 SELECT SUBSTRING(@NS,1,CASE @Pos WHEN 0 THEN LEN(@NS) ELSE @Pos-1 END)  
  
END  
  
RETURN  
END  